#include "comm.h"
int main()
{
    if (mkfifo(IPC_PATH, 0600) != 0)
    {
        cerr << "mkfifo error!!" << endl;
        cout<<strerror(errno)<<endl;
        //cerr << mkfifo(IPC_PATH, 0600) << endl;
        return 1;
    }
    int pipeFd = open(IPC_PATH, O_RDONLY);
    if (pipeFd < 0)
    {
        cerr << "open fifo error" << endl;
        return 1;
    }
#define NUM 1024
    char buffer[NUM];
    while (true)
    {
        memset(buffer, 0, sizeof(buffer));
        ssize_t s = read(pipeFd, buffer, sizeof(buffer));
        if (s > 0)
        {
            buffer[s] = '\0';
            cout << "客户端->服务器# " << buffer << endl;
        }
        else if (s == 0)
        {
            cout << "客户退出啦，我也退出吧" << endl;
            return 1;
        }
        else
        {
            cout << "read: " << strerror(errno) << endl;
        }
    }
    close(pipeFd);
    cout << "服务端退出了" << endl;
    unlink(IPC_PATH);
    return 0;
}